package com.credithc.fastdfs.monitor.service.impl;

import java.util.List;

import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.credithc.fastdfs.api.entity.FileType;
import com.credithc.fastdfs.api.entity.SystemArea;
import com.credithc.fastdfs.api.mapper.FileTypeMapper;
import com.credithc.fastdfs.api.mapper.SystemAreaMapper;
import com.credithc.fastdfs.monitor.service.ParamService;
import com.credithc.framework.core.mybatis.page.PageController;

/**
 * @ClassName: ParamServiceImpl
 * @Description: 系统参数实现
 * @author zhaoc
 * @date 2015年5月21日
 * @time 下午7:12:54
 */
@Service("paramServiceImpl")
public class ParamServiceImpl implements ParamService {
	@Autowired
	private SystemAreaMapper systemAreaMapper;
	
	@Autowired
	private FileTypeMapper fileTypeMapper;
	
	@Override
	public PageController listSysParamInfo(PageController page, SystemArea sys) {
		page.setContent(systemAreaMapper.selectListSystemParamInfo(page, sys));
		return page;
	}

	@Override
	public int addSysParam(SystemArea sys) throws MyException {
		return systemAreaMapper.addSysParam(sys);
	}

	@Override
	public SystemArea getSysParamBySysId(String sysId) throws MyException {
		return systemAreaMapper.getSysParamBySysId(sysId);
	}

	@Override
	public int editSysParam(SystemArea sys) throws MyException {
		return systemAreaMapper.editSysParam(sys);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public int delSysParam(List<String> sysIds) throws MyException {
		for(String sysId : sysIds) {
			systemAreaMapper.delSysParam(sysId);
		}
		return 1;
	}

	@Override
	public PageController listFileParamInfo(PageController page, FileType file) {
		page.setContent(fileTypeMapper.selectListFileParamInfo(page, file));
		return page;
	}

	@Override
	public int addFileParam(FileType file) throws MyException {
		return fileTypeMapper.addFileParam(file);
	}

	@Override
	public FileType getFileParamByFileId(String fileId) throws MyException {
		return fileTypeMapper.getFileParamByFileId(fileId);
	}

	@Override
	public int editFileParam(FileType file) throws MyException {
		return fileTypeMapper.editFileParam(file);
	}

	@Override
	public int delFileParam(List<String> fileIds) throws MyException {
		for(String fileId : fileIds) {
			fileTypeMapper.delFileParam(fileId);
		}
		return 1;
	}

}
